package com.course.chapter5;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

public class CopuntDownLatchDemo {

    private static CountDownLatch countDownLatch =new CountDownLatch(3);

    public static void main(String[] args) {
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(11);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("11");
            countDownLatch.countDown();
        }).start();
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(11);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("22");
            countDownLatch.countDown();
        }).start();
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(11);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("33");
            countDownLatch.countDown();
        }).start();

        try {
            countDownLatch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("全部搞完了");
    }
}
